What is @babel/plugin-transform-regenerator?
The @babel/plugin-transform-regenerator package is a Babel plugin that enables the transformation of generator functions and async functions into ES5-compatible JavaScript code using the regenerator runtime. It allows developers to use these modern features in environments that do not natively support them.
What are @babel/plugin-transform-regenerator's main functionalities?
Transformation of generator functions
This plugin transforms generator functions into ES5 code by converting the generator syntax into a state machine that is compatible with older JavaScript engines.
function* gen() { yield 1; yield 2; yield 3; }
Transformation of async functions
It also transforms async functions into generator functions and then applies the generator function transformation to ensure compatibility with environments that do not support async/await syntax.
async function foo() { await someAsyncFunction(); }
Other packages similar to @babel/plugin-transform-regenerator
regenerator-runtime
The regenerator-runtime package provides the runtime needed to support the generator functions in environments that do not natively support them. It is often used in conjunction with @babel/plugin-transform-regenerator, which handles the syntax transformation.
babel-plugin-transform-async-to-generator
This package is similar to @babel/plugin-transform-regenerator in that it transforms async functions into generator functions. However, it focuses solely on async functions and does not handle generator functions.
fast-async
fast-async is a Babel plugin that transforms async/await functions into ES5-compatible code using Promises instead of generators. It provides an alternative approach to handling async functions and can be faster than regenerator-based transformations.
@babel/plugin-transform-regenerator
Explode async and generator functions into a state machine.
See our website @babel/plugin-transform-regenerator for more information.
Install
Using npm:
npm install --save-dev @babel/plugin-transform-regenerator
or using yarn:
yarn add @babel/plugin-transform-regenerator --dev